#ifndef FILE_SE_GraphicThread_HPP
#define FILE_SE_GraphicThread_HPP

#include <map>

#include "../System.hpp"
#include "Drawable.hpp"

namespace se{
namespace Graphics{
/********************************************//**
 * Render the graphics on the screen.
 * 
 * Usual use : Push all the drawables, from any places,
 * then once all a frame items are pushed, call Swap,
 * and the data  will start rendering, letting you
 * continue to run while it does. Once you are out of
 * the Swap call, you can start to fill it for the next
 * frame.
 *
 * Currently, the framerate is limited by the rendering :
 * if the filling thread(s) run faster than the rendering
 * thread, it will be slowed down by Swap. This is not realy
 * a problem, because it is not realy usefull to calculate
 * something the user won't see.
 * \todo add a triple swap to the ProducerConsumerSwap.
 * to remove the render-caused limitation.
 *
 * The data structure used is curently a multimap/set,
 * but could be optimized for our use.
 * 
 * For now, the interface rendering is not enabled.
 ***********************************************/
class GraphicThread : public System::InterruptibleThread{
	DISALLOW_COPY_AND_ASSIGN(GraphicThread);
	public:
		GraphicThread();
		~GraphicThread();
		void Push(se::Graphics::AnimatedSprite& s);
		void Swap();
		// Some configurations settings (framerate,window size...)
		void SetRenderWindow(sf::RenderWindow& renderWindow);
	private:
		sf::Sprite GetLowestLayerItem();
		void RunThread();
		sf::RenderWindow* m_screen;
		System::ProducerConsumerSwap< std::multimap<uint16_t,Drawable> > m_drawablesSwap;
		boost::mutex m_pushMutex;
		System::ThreadSignal_t m_requestSettingsUpdate;
		// Forbidden :
		void SetFunctor(boost::function<void()> t);
		
};

}//</namespace Graphics>
}//</namespace se>

#undef DRAWABLE

#endif // FILE_SE_GraphicThread_HPP
